package com.zhonghui.controller;

import com.zhonghui.common.core.result.FwResult;
import com.zhonghui.dto.OrderCompleteDto;
import com.zhonghui.dto.OrderCreateDto;
import com.zhonghui.dto.PageDto;
import com.zhonghui.dto.PayOrderDto;
import com.zhonghui.service.OrderService;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author: FL
 * @create: 2024 2024/5/5 12:40
 */
@RestController
@Api(value = "订单信息")
@Slf4j
@Validated
public class OrderController {
    @Autowired
    private OrderService orderService;
    /**
     * 创建订单
     */
    @PostMapping("/orders/create")
    public FwResult createOrder(@RequestBody OrderCreateDto data){
        log.info("创建订单{}",data);

        return orderService.createOrder(data);
    }

    /**
     * 完善订单
     */
    @PutMapping("/orders/complete")
    public FwResult completeOrder(@RequestBody OrderCompleteDto orderCompleteDto){
        log.info("完善订单{}",orderCompleteDto);
        return orderService.completeOrder(orderCompleteDto);
    }

    /**
     * 取消订单
     */
    @PutMapping("/orders/cancel/{orderNo}")
    public FwResult cancelOrder(@PathVariable String orderNo){
        log.info("取消订单{}",orderNo);
        return orderService.cancelOrder(orderNo);
    }

    /**
     * 获取支付信息
     */
    @GetMapping("/orders/pay/{orderNo}")
    public FwResult getPayInfo(@PathVariable String orderNo){
        log.info("获取支付信息{}",orderNo);
        return orderService.getPayInfo(orderNo);
    }

    /**
     * 订单支付
     * @return
     */
    @PutMapping("/orders/pay")
    public FwResult payOrder(@RequestBody PayOrderDto payOrderDto){
        log.info("订单支付{}",payOrderDto);
        return orderService.payOrder(payOrderDto);
    }

    /**
     * 获取订单列表
     * @param pageDto
     * @return
     */
   @PostMapping("/orders")
   public FwResult getOrderPage(@RequestBody PageDto pageDto){
       log.info("获取订单列表");

       return orderService.getOrderPage(pageDto);
   }

   @GetMapping("/orders/{orderNo}")
   public FwResult getOrderByOrderNo( @PathVariable String orderNo){
       log.info("获取订单详情:{}",orderNo);
       return orderService.getOrderByOrderNo(orderNo);
   }


}
